<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue学习</title>
    <script src="./js/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <h3>用户登录</h3>
      <hr />
      <div>
        账号：
        <input type="text" v-model="loginForm.username" />
      </div>
      <div>
        密码：
        <input type="text" v-model="loginForm.password" />
      </div>
      <div>
        <button @click="doLogin">进入系统</button>
      </div>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            loginForm: {
              username: '',
              password: ''
            }
          }
        },
        methods: {
          async doLogin() {
            let res = await fetch('http://localhost:9000/api/login', {
              method: 'post',
              body: JSON.stringify(this.loginForm),
              headers: {
                'Content-Type': 'application/json'
              }
            }).then((ret) => ret.json())

            console.log(res)
          }
        }
      })
      app.mount('#app')
    </script>
  </body>
</html>
